package cn.mesmile.security.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zb
 * @date 2020/4/5 15:13
 * @Description:
 */
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        /**
         * {"accountNonExpired":true,"accountNonLocked":true,
         * "authorities":[{"authority":"ROLE_ADMIN"},{"authority":"ROLE_USER"}],
         * "credentialsNonExpired":true,"enabled":true,"username":"admin"}
         */
        Object principal = authentication.getPrincipal();

        /**
         *  用户名
         */
        String username = authentication.getName();

        return "hello spring security";
    }

}
